<link rel="stylesheet" href="{{URL::asset('/layui/css/layui.css')}}">
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
    <legend>Login</legend>
</fieldset>
<style>
    input{
        width:70% !important;
    }
</style>
<form class="layui-form" action="" lay-filter="example">
    <div class="layui-form-item">
        <label class="layui-form-label">账号</label>
        <div class="layui-input-block">
            <input type="text" name="username" lay-verify="title" autocomplete="off" placeholder="请输入账号" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码框</label>
        <div class="layui-input-block">
            <input type="password" name="password" placeholder="请输入密码" autocomplete="off" class="layui-input">
        </div>
    </div>

{{--    <div class="layui-form-item">--}}
{{--        <label class="layui-form-label">记住密码</label>--}}
{{--        <div class="layui-input-block">--}}
{{--            <input type="checkbox" name="close" lay-skin="switch" lay-text="ON|OFF">--}}
{{--        </div>--}}
{{--    </div>--}}

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="button" class="layui-btn layui-btn-normal login" id="LAY-component-form-setval">登陆</button>
            <button type="button" class="layui-btn layui-btn-normal register" id="LAY-component-form-getval">注册</button>
        </div>
    </div>
</form>
<script src="{{URL::asset('/layui/layui.js')}}"></script>
<script>
    layui.use(['layer','form'], function(){
        var $ = layui.$; //layui 起止条件 （使用layui先声明）
        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
        var signInurl = "{{url('admin/login/signIn')}}";  //访问登陆路由链接
        var register = "{{url('admin/login/register')}}";//访问注册路由链接

        //注册
        $('.register').on('click', function(){
            var obj = {};
            obj.username = $('input[name=username]').val();
            obj.password = $('input[name=password]').val();
            var userDateStr = JSON.stringify(obj);
            $.ajax({
                url:register,
                type:'post',
                data:{
                    'data':userDateStr,
                    '_token':'{{csrf_token()}}',
                    'type':'1',
                },
                success:function(data){
                    var info = JSON.parse(data);
                    if(info.code == 0){
                        layer.confirm("状态码："+info.code+",信息："+info.msg, {
                            btn: ['知道了'] //可以无限个按钮
                        }, function(index, layero){
                            parent.location.reload(); // 刷新父级页面
                            parent.layer.close(index); //关闭当前页面
                        });
                        return;
                    }
                    layer.alert("状态码："+info.code+",信息："+info.msg);return;
                },
            })
        });
        //登陆
        $('.login').on('click', function(){
            var obj = {};
            obj.username = $('input[name=username]').val();
            obj.password = $('input[name=password]').val();
            var userDateStr = JSON.stringify(obj);
            $.ajax({
                url:signInurl,
                type:'post',
                data:{
                    'data':userDateStr,
                    '_token':'{{csrf_token()}}',
                    'type':'1',
                },
                success:function(data){
                    var info = JSON.parse(data);
                    if(info.code == 0){
                        layer.confirm("状态码："+info.code+",信息："+info.msg, {
                            btn: ['知道了'] //可以无限个按钮
                        }, function(index, layero){
                            parent.location.reload(); // 刷新父级页面
                            parent.layer.close(index); //关闭当前页面
                        });
                        return;
                    }
                    layer.alert("状态码："+info.code+",信息："+info.msg);return;
                },
            })
        });
    })
</script>
